<template>
  <div class="app-container">
    <!--工具栏-->
    <crudOperation :permission="permission">
      <el-button
        slot="left"
        class="filter-item"
        size="mini"
        type="primary"
        @click="exportData()"
      >
        导出
      </el-button>
    </crudOperation>
    <div class="head-container">
      <div v-if="!crud.props.searchToggle">
      </div>
      <el-dialog v-dialog-drag style="width: 80vm" title="搜索"   close-on-click-modal :visible.sync="crud.props.searchToggle"
        width="70%">
        <el-form size="small" class="formClass" label-width="85px" >
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" >
              <el-form-item label="业务日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.startDate"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.endDate"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" >
              <el-form-item label="装车日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.loadStartDate"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.loadEndDate"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" >
              <el-form-item label="核销日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.cancelStartDate"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.cancelEndDate"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
              <el-form-item label="客户">
                <zSelect multiple :value.sync="query.customerIds"  url="api/dropDown/basCustomerList"
                         style="width:  100%;"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
              <el-form-item label="驾驶员">
                <table-select
                  :tableColumns="
                  [
                  {prop:'name',label:'司机名称'},
                  ]
                  "
                  labelKey="name"
                  valueKey="id"
                  width="400"
                  :params="{businessAttr:'5'}"
                  :value.sync="query.driverUserIds"
                  placeholder="请选择驾驶员"
                  url="/api/dropDown/sysUserList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
              <el-form-item label="跟车员">
                <table-select
                  :tableColumns="
                  [
                  {prop:'name',label:'跟车名称'},
                  ]
                  "
                  labelKey="name"
                  valueKey="id"
                  width="400"
                  :params="{businessAttr:'6'}"
                  :value.sync="query.followUserIds"
                  placeholder="请选择跟车员"
                  url="/api/dropDown/sysUserList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="单据类型">
                <el-select v-model="query.orderType" collapse-tags  class="edit-input" placeholder="请选择单据类型" style="width: 100%;">
                  <el-option label="全部" value=""/>
                  <el-option label="销售订单" value="1"/>
                  <el-option label="销售退货单" value="2"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="单据编号">
                <el-input v-model="query.orderCode" placeholder="输入单据编号进行搜索"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="配送单号">
                <el-input v-model="query.loadCode" placeholder="输入配送单号进行搜索"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row class="flex fow-reverse" >
            <el-button class="filter-item"  size="mini" type="primary" @click="queryReport">搜索</el-button>
            <el-button class="filter-item" plain   size="mini" type="primary"
                       @click="resetQuery" >重置</el-button>
          </el-row>
        </el-form>
      </el-dialog>

      <!--表格渲染-->
      <el-table ref="table" border v-loading="crud.loading" :data="crud.data" size="small"
                style="width: 100%;" v-if="isShowTable"
                @header-dragend="changeColWidth"
                show-summary
                height="700"
                :summary-method="crud.sumRow"
                @row-click="crud.selectRow"
                :row-style="crud.rowClass"
                :row-class-name="crud.tableRowClassName"
                @contextmenu.native="showMenu"
                @selection-change="crud.selectionChangeHandler"
                @row-dblclick="crud.toDetailPlus('reportSendReceiptDetail',$event.orderId)">
        <el-table-column type="selection" width="55" />
        <el-table-column type="index" width="55" label="序号"/>
        <el-table-column v-if="columns.visible('busDate')" prop="busDate" label="业务日期" />
        <el-table-column v-if="columns.visible('orderType')" prop="orderType" label="单据类型" />
        <el-table-column v-if="columns.visible('orderCode')" prop="orderCode" label="单据编号" />
        <el-table-column v-if="columns.visible('customerCode')" prop="customerCode" label="客户编号" />
        <el-table-column v-if="columns.visible('customerName')" prop="customerName" label="客户名称" />
        <el-table-column v-if="columns.visible('acceptBoxCount')" prop="acceptBoxCount" label="验收箱数" />
        <el-table-column v-if="columns.visible('acceptTaxAmount')" prop="acceptTaxAmount" label="验收金额" />
        <el-table-column v-if="columns.visible('loadDate')" prop="loadDate" label="装车日期" />
        <el-table-column v-if="columns.visible('loadCode')" prop="loadCode" label="装车单号" />
        <el-table-column v-if="columns.visible('cancelStatus')" prop="cancelStatus" label="核销状态" />
        <el-table-column v-if="columns.visible('cancelAmount')" prop="cancelAmount" label="已核销金额" />
        <el-table-column v-if="columns.visible('orderRemark')" prop="orderRemark" label="单据备注" />
      </el-table>
      <!--分页组件-->

      <pagination/>
    </div>
  </div>
</template>

<script>
import crudReportDriverLoad from '@/api/erp/reportSendReceipt'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import {getBasGoodsTypeTree} from "@/api/erp/basGoodsType";
import Treeselect from '@riophae/vue-treeselect'
import {get} from '@/api/erp/reportSendReceipt'
import { publicListKey } from "@/utils/key";
import {getHeaderProperties} from "@/api/erp/headerProperties";
import {tablemixins} from "@/mixins/tablemixins";
import  jTableColumnConfig  from "@/components/jTableColumnConfig/jTableColumnConfig";
import {getAreaTree} from "@/api/erp/basCustomerArea";
import {getCustomerTypeTree} from "@/api/erp/basCustomerType";
import tableSelect from '@/components/tableSelect/tableSelect'
import {download} from '@/api/data'
import {downloadFile} from '@/utils/index'


// crud交由presenter持有
const defaultCrud = CRUD({ title: '送货收款报表',
  optShow: {
    add: false,
    edit: false,
    del: false,
    download: true,
    leadingIn: false,
    enable: false,
    disable: false,
    pass: false,
    reject: false,
    invalid: false,
    recover: false,
    downloadDetail: false,
    print: false,
    printDetail: false
  },
  query:{
    startDate:new Date().toISOString().split('T')[0],
    endDate:new Date().toISOString().split('T')[0]
  },
  url: 'api/reportSendReceipt', sort: '',
  crudMethod: { ...crudReportDriverLoad }})
const defaultForm = { busDate: null, orderType: null, orderId: null, orderCode: null, orderName: null, orderStatus: null, customerId: null, customerCode: null, customerName: null, pCustomerId: null, pCustomerCode: null, pCustomerName: null, mCustomerId: null, mCustomerCode: null, mCustomerName: null, deptId: null, deptCode: null, deptName: null, userId: null, userCode: null, userName: null, warehouseId: null, warehouseCode: null, warehouseName: null, orderRemark: null, goodsId: null, goodsCode: null, goodsName: null, packageType: null, barcode: null, boxBarcode: null, helpSign: null, model: null, goodsBrandId: null, goodsBrandCode: null, goodsBrandName: null, goodsTypeId: null, goodsTypeCode: null, goodsTypeName: null, goodsTagId: null, goodsTagCode: null, goodsTagName: null, boxUnitId: null, boxUnitCode: null, boxUnitName: null, boxUnitCount: null, boxNum: null, mainUnitId: null, mainUnitCode: null, mainUnitName: null, mainUnitCount: null, mainNum: null, goodsCount: null, boxCount: null, taxPrice: null, noTaxPrice: null, taxBoxPrice: null, noTaxBoxPrice: null, taxAmount: null, noTaxAmount: null, tax: null, acceptGoodsCount: null, acceptBoxCount: null, acceptBoxNum: null, acceptMainNum: null, acceptTaxAmount: null, acceptNoTaxAmount: null, acceptTax: null, cancelAmount: null, unCancelAmount: null, goodsRemark: null, createUserId: null, createUserCode: null, createUserName: null, createTime: null, auditUserId: null, auditUserCode: null, auditUserName: null, auditTime: null, closeUserId: null, closeUserCode: null, closeUserName: null, closeTime: null, acceptDate: null, acceptUserId: null, acceptUserCode: null, acceptUserName: null, cancelDate: null, cancelUserId: null, cancelUserCode: null, cancelUserName: null, id: null }
export default {
  name: 'ReportSendReceipt',
  components: { pagination, crudOperation, rrOperation, udOperation,Treeselect,jTableColumnConfig, tableSelect },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(),publicListKey,tablemixins],
  dicts:[],
  mounted(){
    const date  = new Date().toISOString().split('T')[0]
    this.dataExtent[0] = date
    this.dataExtent[1] = date
    this.crud.props.searchToggle =false
    this.queryReport()
  },
  created() {
    this.$set(this.query,'startDate',new Date().toISOString().split('T')[0])
    this.$set(this.query,'endDate',new Date().toISOString().split('T')[0])
    this.crud.optShow = {
      download: false
    }
  },
  data() {
    return {
      customerIds:[],
      driverUserIds:[],
      followUserIds:[],
      orderType:'',
      orderCode:'',
      loadCode:'',
      permission: {
        export: ['admin', 'reportSendReceipt:export'],
        exportDetail: ['admin', 'reportSendReceipt:exportDetail'],
      },
      rules: {
      },
    }
  },
  updated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  watch: {

  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
    init(){
      this.page = 1
    },
    onGet(){
      const that =this
      let { page,size } = this.crud.page
      page =  1
      get({...this.query,page,size}).then(res=>{
        that.crud.data = res.data.content
        that.crud.page.total = res.data.totalElements
        console.log(that.total)
      })
    },
    resetQuery(){
      this.customerIds = []
      this.driverUserIds = []
      this.followUserIds = []
      this.orderType = ''
      this.orderCode = ''
      this.loadCode = ''
      this.crud.resetQuery()
    },
    queryReport(){
      this.init()
      this.crud.toQuery()
      this.crud.props.searchToggle = false
    },
    exportData() {
      this.crud.query.orderIds = ''
      this.crud.selections.forEach(item => {
        this.crud.query.orderIds += item.orderId + ','
      })
      const params = {
        orderIds: this.crud.query.orderIds,
        ...this.query
      }
      download('api/reportSendReceipt/export', params).then(result => {
        downloadFile(result, this.crud.title + '数据', 'xlsx')
        this.crud.downloadDetailLoading = false
      }).catch(() => {
        this.crud.downloadDetailLoading = false
      })
    },
  }
}
</script>

<style lang="scss" scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
  .flex{
    display: flex;
  }
  .fow-reverse{
    flex-direction: row-reverse;
  }
  .codeJump{
    background-image:-webkit-linear-gradient(top,yellow,#ff00fb);
    -webkit-background-clip:text;
    -webkit-text-fill-color:transparent;
    cursor: pointer;
  }
</style>
